package com.tjcd.project.library_base.common.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.ViewGroup;

import com.tjcd.project.library_base.R;


/**
 * @Author jiangKunKun
 * @CreateDate 2022/8/22
 * @Description loading 弃用
 * @SpittingGrooves
 */
public class LoadingUtil {
    private static volatile Dialog sFullScreen = null;

    public static void show(Context context) {
        if (sFullScreen == null || !sFullScreen.isShowing()) {
            synchronized (LoadingUtil.class) {
                if (sFullScreen == null || !sFullScreen.isShowing()) {
                    sFullScreen = new Dialog(context);
                    sFullScreen.setContentView(R.layout.dialog_loading);
                    sFullScreen.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    sFullScreen.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    sFullScreen.show();
                }
            }
        }
    }

    /**
     * 隐藏
     */
    public static void hide() {
        if (null != sFullScreen && sFullScreen.isShowing()) {
            sFullScreen.hide();
        }
    }

    /**
     * 关闭弹窗
     */
    public static void dismiss() {
        if (null != sFullScreen && sFullScreen.isShowing()) {
            sFullScreen.dismiss();
            sFullScreen = null;
        }
    }

    /**
     * 关闭弹窗
     * cancel也会调用dismiss
     * 触发回调 onCancelListener
     */
    public static void cancel() {
        if (null != sFullScreen) {
            hide();
            sFullScreen.cancel();
        }
        sFullScreen = null;
    }
}
